package com.denlaku.longan.controller.impl;

import com.denlaku.longan.controller.ObjectTagSetController;
import com.denlaku.longan.http.Resp;
import com.denlaku.longan.http.Return;
import com.denlaku.longan.qo.ObjPermQuery;
import com.denlaku.longan.qo.Query;
import com.denlaku.longan.service.ObjectTagSetService;
import com.denlaku.longan.util.SnowflakeUtils;
import com.denlaku.longan.vo.ObjectTagSet;
import com.denlaku.longan.vo.PageBy;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author tianx
 */
@RestController
public class ObjectTagSetControllerImpl implements ObjectTagSetController {
    @Autowired
    private ObjectTagSetService objectTagSetService;

    @Override
    public Return<Long> add(ObjectTagSet objectTagSet) {
        objectTagSet.setId(SnowflakeUtils.nextId());
        objectTagSetService.add(objectTagSet);
        return Resp.success(objectTagSet.getId());
    }

    @Override
    public Return<Long> update(ObjectTagSet objectTagSet) {
        objectTagSetService.update(objectTagSet);
        return Resp.success(objectTagSet.getId());
    }

    @Override
    public Return<ObjectTagSet> get(Query query) {
        ObjectTagSet objPermTagSet = objectTagSetService.get(query);
        return Resp.success(objPermTagSet);
    }

    @Override
    public Return<List<ObjectTagSet>> pageList(Query query, PageBy pageBy) {
        PageHelper.startPage(pageBy.getPage(), pageBy.getSize());
        List<ObjectTagSet> list = objectTagSetService.list(query);
        return Resp.success(list);
    }

    @Override
    public Return<List<ObjectTagSet>> search(Query query) {
        List<ObjectTagSet> list = objectTagSetService.search(query);
        return Resp.success(list);
    }

    @Override
    public Return<Void> delete(ObjPermQuery query) {
        if (query.getId() != null) {
            objectTagSetService.delete(query);
        }
        return Resp.success();
    }
}
